package com.waya.web.browser;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.WindowManager;

public class ShowDialogActivity extends AppCompatActivity {


    public static final String KEY_WIDTH = "key_width";
    public static final String KEY_HEIGHT = "key_width";
    public static final String KEY_URL = "key_url";

    private int mWidth;
    private int mHeight;
    private String mUrl;
    private WayeWebViewDialog mWbDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getIntentData();
        if (mWidth != -1 || mHeight != -1) {
            getWindow().setLayout(dp2px(mWidth), dp2px(mWidth));
        }
        mWbDialog = new WayeWebViewDialog(this, mUrl, dp2px(mWidth), dp2px(mHeight));
        mWbDialog.show();
    }

    public int dp2px(int dp) {
        return Math.round(dp * Resources.getSystem().getDisplayMetrics().density);
    }

    public void getIntentData() {
        mWidth = getIntent().getIntExtra(KEY_WIDTH, WindowManager.LayoutParams.MATCH_PARENT);
        mHeight = getIntent().getIntExtra(KEY_HEIGHT, WindowManager.LayoutParams.MATCH_PARENT);
        mUrl = getIntent().getStringExtra(KEY_URL);
        if (TextUtils.isEmpty(mUrl)) {
            throw new NullPointerException("webview  url must not be null...");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        if (mWbDialog != null && mWbDialog.isShowing()) {
//            mWbDialog.dismiss();
//        }
        System.exit(0);
    }
}
